﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using       SmartParking.Entities;
using SmartParking.IService;
using SmartParking.Service;

namespace SmartParking.Service
{
    public class UserService : BaseService, IUserService
    {
        public UserService(DbContext context)
            : base(context)
        {

        }
        public bool CheckUserName(string userName)
        {
            return this.Query<SysUser>(u => u.UserName == userName).Count() > 0;
        }

        public SysUser Login(string username, string password)
        {
           var users=
                this.Set<SysUser>().Include(r=>r.Roles).Where(u=>u.UserName==username&&u.Password==password)
               .FirstOrDefault();
            return users;
        }

        public IEnumerable<SysUser> GetUsers(string key)
        {
            // 需要将搜索关键词加入判断。。。。。。
            return this.Set<SysUser>().Include(r=>r.Roles).Where(m =>

                string.IsNullOrEmpty(key) ||

                m.UserName.Contains(key) ||

                m.Address.Contains(key)
            );
        }
    }
}
